﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.EndModelingEntityLevel.CApEMEndModelingMultipleComponentsEntityLevelApp
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.EndModelingEntityLevel;

internal class CApEMEndModelingMultipleComponentsEntityLevelApp : CApEMEndModelingEntityLevelApp
{
  private TxObjectList<ITxComponent> components;

  public CApEMEndModelingMultipleComponentsEntityLevelApp(TxObjectList<ITxComponent> components)
  {
    this.components = components;
  }

  public override bool ComponentEndModeling()
  {
    return this.DoesAllComponentCanBeEndModelingWithoutLosingReferencedEntities();
  }

  private bool DoesAllComponentCanBeEndModelingWithoutLosingReferencedEntities()
  {
    bool flag = true;
    foreach (ITxComponent component in (Collection<ITxComponent>) this.components)
    {
      if (!this.DoesComponentCanBeEndModelingWitoutLosingReferencedEntities(component))
      {
        flag = false;
        break;
      }
    }
    return flag;
  }

  private bool DoesComponentCanBeEndModelingWitoutLosingReferencedEntities(ITxComponent component)
  {
    return component.RepresentationType == 4 || !this.DoesComponentContainsUnpreservedReferencedEntities(component);
  }

  private bool DoesComponentContainsUnpreservedReferencedEntities(ITxComponent component)
  {
    bool flag = false;
    foreach (ITxDetailedRepresentation referencedEntity in (Collection<ITxObject>) component.GetReferencedEntities(new TxObjectList()))
    {
      if (referencedEntity != null && !referencedEntity.Preserved)
      {
        flag = true;
        break;
      }
    }
    return flag;
  }
}
